<?php
namespace app\components;
use Yii;
use Redis;
/**
 * redis 连接类
 * @author LBW
 *
 */
class RedisHelper
{
    private  $redis;
    
    private static $instance;
    
    private function __construct()
    {
        $this->redis = new Redis();
        $this->redis->connect(Yii::$app->params['redis']['host'],Yii::$app->params['redis']['port']);
    }
    
    public static function getInstance()
    {
        if(!self::$instance instanceof self)
        {
            self::$instance = new self();
        }
        return self::$instance;
        
    }
    
    public function getRedisConnect()
    {
        return $this->redis;
    }
    
    private function __clone()
    {
        
    }
    
    public function __destruct()
    {
        self::$instance->redis->close();
        self::$instance = null;
    }
}